package de.baumann.browser.present

import de.baumann.browser.api.OdinObserver
import de.baumann.browser.api.net.vo.PacketRecord
import de.baumann.browser.base.BasePresenter
import de.baumann.browser.iview.IPackRecordView
import de.baumann.browser.model.PackModel

class PackRecordPresenter : BasePresenter<IPackRecordView>() {
    private val packModel = PackModel()

    fun getRecivedPacks() {
        this.packModel.recivedPacks
                .subscribe(object : OdinObserver<PacketRecord>(view) {
                    override fun onSuccess(data: PacketRecord) {
                        if (view != null) {
                            view.setPacketList(data.list)
                            if (data.totalAmount == null) {
                                view.setTotalAmount("0")
                            } else {
                                view.setTotalAmount(data.totalAmount)
                            }
                        }
                    }
                })
    }


    fun getSendPacks() {
        this.packModel.sendPacks
                .subscribe(object : OdinObserver<PacketRecord>() {
                    override fun onSuccess(data: PacketRecord?) {
                        if (view != null && data != null) {
                            if (data.totalAmount == null) {
                                view.setTotalAmount("0")
                            } else {
                                view.setTotalAmount(data.totalAmount)
                            }
                            view.setPacketList(data.list)
                        }
                    }
                })
    }
}